﻿using Basic.WxApiRemoteModel.WxMini;
using Basic.WxApiRemoteModel.WxMini.Model;
using Basic.WxApiService.Interface;
using Basic.WxApiService.WxModel.Mini;
using WeDonekRpc.Client.Interface;
using WeDonekRpc.Helper;

namespace Basic.WxService.RpcEvent
{
    internal class WxMiniEvent : IRpcApiService
    {
        private readonly IWxMiniService _Service;

        public WxMiniEvent (IWxMiniService service)
        {
            this._Service = service;
        }
        public WxMiniEncryptKey[] GetMiniEncryptKey (GetMiniEncryptKey obj)
        {
            MiniEncryptKey[] keys = this._Service.GetEncryptKey(obj.WxAppId, obj.UserOpenId, obj.Signature);
            return keys.ConvertAll(c => new WxMiniEncryptKey
            {
                CreateTime = c.create_time,
                EncryptKey = c.encrypt_key,
                Expire = c.expire_in,
                Iv = c.iv,
                Version = c.version
            });
        }
        public bool CheckWxEncrypted (CheckWxEncrypted obj)
        {
            return this._Service.CheckEncrypted(obj.WxAppId, obj.EncryptedData);
        }
        public bool CheckMiniSession (CheckMiniSession obj)
        {
            return this._Service.CheckSession(obj.WxAppId, obj.OpenId, obj.Signature);
        }
        public MiniPhone GetMiniUserPhone (GetMiniUserPhone obj)
        {
            MiniUserPhone res = this._Service.GetUserPhone(obj.WxAppId, obj.Code);
            return new MiniPhone
            {
                Country = res.countryCode,
                Phone = res.phoneNumber,
                PurePhone = res.purePhoneNumber,
            };
        }
    }
}
